﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Codebricks.Db.Attributes;
using Codebricks.Db.Interface;
using KBVault.DAL.Repository;

namespace KBVault.DAL.Entities
{
    [MySqlTable("categories")]
    public class Category:IMysqlTable
    {
        [MySqlPrimaryKey(true)]
        [MySqlField("Id")]
        public int Id { get; set; }

        [MySqlField("Name")]
        public string Name { get; set; }

        [MySqlField("Is_Hot")]
        public int IsHot { get; set; }

        public List<Article> Articles
        {
            get
            {
                return CategoryRepository.Articles(Id);
            }
        }

        public List<Article> PublicArticles
        {
            get
            {
                return CategoryRepository.Articles(Id).Where(a => a.IsDraft == 0 && DateTime.Now >= a.PublishStartDate && DateTime.Now <= a.PublishEndDate).ToList<Article>();
            }
        }

        public int ArticleCount
        {
            get
            {
                return CategoryRepository.ArticleCount(Id);
            }
        }
        
        public int PublicArticleCount
        {
            get
            {
                return CategoryRepository.PublicArticleCount(Id);
            }
        }
    }
}
